<%--
  Created by IntelliJ IDEA.
  User: Cc
  Date: 2020/12/30
  Time: 16:51
  To change this template use File | Settings | File Templates.
--%>
<%
    String path = request.getContextPath();
    String basePath = request.getScheme() + "://" +
            request.getServerName() + ":" + request.getServerPort() + path + "/";
%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<!DOCTYPE html>
<html>

<head>
    <meta charset="UTF-8">
    <title>添加</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport"
          content="width=device-width,user-scalable=yes, minimum-scale=0.4, initial-scale=0.8,target-densitydpi=low-dpi"/>
    <link rel="shortcut icon" href="<%=basePath%>static/favicon.ico" type="image/x-icon"/>
    <link rel="stylesheet" href="<%=basePath%>static/css/font.css">
    <link rel="stylesheet" href="<%=basePath%>static/css/xadmin.css">
    <script type="text/javascript" src="<%=basePath%>static/js/jquery-3.3.1.min.js"></script>
    <script type="text/javascript" src="<%=basePath%>static/lib/layui/layui.js" charset="utf-8"></script>
    <script type="text/javascript" src="<%=basePath%>static/js/xadmin.js"></script>
</head>

<body>
<div class="x-body">
    <form class="layui-form">
        <div class="layui-form-item">
            <label for="username" class="layui-form-label">
                <span class="x-red">*</span>登录名
            </label>
            <div class="layui-input-inline">
                <input readonly type="text" id="username" name="username" required=""
                       autocomplete="off" class="layui-input">
            </div>
            <div class="layui-form-mid layui-word-aux">
                <span class="x-red">*</span>登入名
            </div>
        </div>


        <div class="layui-form-item">
            <label for="password" class="layui-form-label">
                密码
            </label>
            <div class="layui-input-inline">
                <input type="password" id="password" name="password" required=""
                       autocomplete="off" class="layui-input">
            </div>
        </div>
        <div class="layui-form-item">
            <label for="hobby" class="layui-form-label">
                爱好
            </label>
            <div class="layui-input-inline">
                <input type="text" id="hobby" name="hobby"
                       autocomplete="off" class="layui-input">
            </div>
        </div>
        <div class="layui-form-item">
            <label for="L_repass" class="layui-form-label">
            </label>
            <button class="layui-btn" id="L_repass" type="button" onclick="updateUserByUsername()">
                修改
            </button>
        </div>
    </form>
</div>
<script>
    $(document).ready(function () {
        $('#username').val(localStorage.getItem('username'));
        $('#password').val(localStorage.getItem('password'));
        $('#hobby').val(localStorage.getItem('hobby'));
    })

    function updateUserByUsername() {
        $.ajax({
            url: '../user/updateUserByUsername',
            dataType: 'json',
            type:'post',
            data:{
                "username":$('#username').val(),
                "password":$('#password').val(),
                "hobby":$('#hobby').val()
            },
            success: function (res) {
            let msg = res.updateInfo;
            if(msg=='修改成功'){
                layer.alert('修改成功',{icon:6},function(){
                    let index = parent.layer.getFrameIndex(window.name)
                    parent.layer.close(index);
                    parent.location.reload()

                });
            }
                console.log(res);
            },
            error: function (res) {
                alert("服务器错误")
            }
        })
    }
</script>

</body>

</html>